package com.tzq.JAVABEAN;

import java.sql.ResultSet;
import java.util.ArrayList;

public class GetPersonInfo {
	public String[] Get(String userid){
		String totalVideo = "";         // total Video
		String totalImage = "";         //total Image
		String totalBlog ="";          //total Blog

		String userName="";         // UserName
		String homeProvince="";        // Home Province id
		String grade="";           // User grade
		String sex="";            //User Sex
		String age="";           //User age
		String schoolProvince="";     //User school province
		String collegeName="";    // User College NAME
		String schoolName="";      // User school Name
		String email="";              // User Email
		String description = "";        //USER DESCRIPTION
		String head ="";           //User head Image Name
		try{
		    ConnectDB sql =new ConnectDB();
		    ResultSet rsUserInfo = sql.executeQuery("select * from Userinfo U,Schools S where U.UserID = "+userid+" and U.SchoolID=S.SchoolID");  //Get ResultSet of User INFO
		    ResultSet rstotalvideo = sql.executeQuery("select count(*) as A from Videos where UserID="+userid+"");         //Get ResultSet of User Video
		    ResultSet rstotalImage = sql.executeQuery("select count(*) as B from Images where UploaderID="+userid+"");      //Get ResultSet of User Image
		    ResultSet rstotalBlog = sql.executeQuery("select count(*) as C from Blog where AuthorID="+userid+"");           //Get ResultSet of User Blog
		
		    if(rstotalvideo.next()){
			    totalVideo = rstotalvideo.getString("A");
		    }
		    
		
		    if(rstotalImage.next()){
			    totalImage = rstotalImage.getString("B");
		    }
		
		    if(rstotalBlog.next()){
			    totalBlog = rstotalBlog.getString("C");
		    }

		    if(rsUserInfo.next()){
			    userName = rsUserInfo.getString("UserName");
			    homeProvince =rsUserInfo.getString("HomeProvince");
			    grade = rsUserInfo.getString("Grade");
			    sex = rsUserInfo.getString("Sex");
			    age = rsUserInfo.getString("Age");
			    schoolProvince = rsUserInfo.getString("SchoolProvince");
			    collegeName = rsUserInfo.getString("CollegeName");
			    schoolName = rsUserInfo.getString("SchoolName");
			    email = rsUserInfo.getString("Email");
			    description = rsUserInfo.getString("UserDescript");
			    head = rsUserInfo.getString("head");
			    
		    }
		}catch(Exception e){
			e.printStackTrace();
		}
		String[] userinfoStrings = {totalVideo,totalImage,totalBlog,userName,homeProvince,grade,sex,age,schoolProvince,collegeName,schoolName,email,head,description};
		return userinfoStrings;
	}
	
	public int[] addfriend(String sessionidString,String useridString){
		int[] temp ={0,0};
		ConnectDB sql = new ConnectDB();
		boolean isHasFriend = sql.isHasDatas("select * from Friends where MyID="+sessionidString+" and FriendID="+useridString+" and State=1");
		boolean isHasFriendApply = sql.isHasDatas("select * from Friends where MyID="+sessionidString+" and FriendID="+useridString+" and State=0");
		sql.closeConnection();
		if(isHasFriend){
			temp[0]=1;
		}
		if(isHasFriendApply){
			temp[1]=1;
		}
		return temp;
	}

}
